<!DOCTYPE html>
<html>
<head>
    <title>StudentAttendenceDetailsTable</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" href="../../css/font-awesome.min.css">
    <link rel="stylesheet" href="../../plugins/jqgrid/ui.jqgrid-bootstrap.css">
    <link rel="stylesheet" href="../../plugins/ztree/css/metroStyle/metroStyle.css">
    <link rel="stylesheet" href="../../css/main.css">
    <script src="../../libs/jquery.min.js"></script>
    <script src="../../plugins/layer/layer.js"></script>
    <script src="../../libs/bootstrap.min.js"></script>
    <script src="../../libs/vue.min.js"></script>
    <script src="../../libs/validator.min.js"></script>
    <script src="../../plugins/jqgrid/grid.locale-cn.js"></script>
    <script src="../../plugins/jqgrid/jquery.jqGrid.min.js"></script>
    <script src="../../plugins/ztree/jquery.ztree.all.min.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../libs/My97DatePicker/4.8/WdatePicker.js"></script>
</head>
<body>
<div id="rrapp" v-cloak>
    <div v-show="showList">
        <div class="row">
            <div class="form-group col-sm-2 set-paddingLeft">
                <input type="text" class="form-control" v-model="q.key" @keyup.enter="query" placeholder="学生名字/所属学院/所属班级">
            </div>
            <!--<div class="form-group col-sm-2">-->
                <!--<select  class="form-control" id="College">-->
                <!--</select>-->
            <!--</div>-->
            <!--<div class="form-group col-sm-2">-->
                <!--<select  class="form-control" id="Profession">-->
                    <!--<option value=''>请先选择学院</option>-->
                <!--</select>-->
            <!--</div>-->
            <div class="form-group col-sm-2">
                <select  class="form-control" id="Class">
                    <option value=''>请先选择学院</option>
                </select>
            </div>
            <!--<div class="form-group col-sm-2 set-paddingLeft">-->
                <!--<select  class="form-control" id="Student">-->
                    <!--<option value=''>请先选择班级</option>-->
                <!--</select>-->
            <!--</div>-->
            <!--<div class="form-group col-sm-2">-->
                <!--<select  class="form-control" id="Course">-->
                    <!--<option value=''>请先选择班级</option>-->
                <!--</select>-->
            <!--</div>-->
            <div class="form-group col-sm-2">
                <select  class="form-control" id="State">
                    <option value=''>全部</option>
                    <option value='出勤'>出勤</option>
                    <option value='迟到'>迟到</option>
                    <option value='旷课'>旷课</option>
                    <option value='早退'>早退</option>
                    <option value='请假'>私假</option>
                    <option value='请假'>病假</option>
                    <option value='请假'>公假</option>
                </select>
            </div>
        </div>
        <div class="row">
            <div class="form-group col-sm-2 set-paddingLeft">
                <input type="text" class="form-control" onfocus="WdatePicker()" id="startDate" name="startDate" placeholder="开始时间"/>
            </div>
            
            <div class="form-group col-sm-2">
                <input type="text" class="form-control" onfocus="WdatePicker()" id="endDate" name="endDate"  placeholder="结束时间"/>
            </div>
            <div class="btn-container">
                <span  class="normal-btn normal-color" onclick="setDate('1')">今日</span>
                <span  class="normal-btn normal-color" onclick="setDate('2')">本周</span>
                <span  class="normal-btn normal-color" onclick="setDate('3')">本月</span>
            </div>
        </div>
            <div class="btn-container" style="margin-bottom: 15px">
                <a class="normal-btn search-color" @click="query">查询</a>
                <a class="normal-btn normal-color" id="exportExcel">导出</a>
            </div>
            
            <!--<a class="btn btn-primary" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</a>-->
            <!--<a class="btn btn-primary" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</a>-->
            <!--<a class="btn btn-primary" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</a>-->
        </div>
        <table id="jqGrid"></table >
        <div id="jqGridPager"></div>
    </div>
<script>
    $(function () {
        $("#jqGrid").jqGrid({
            url: baseURL + 'StudentAttendenceDetails/getMyStudentAttendenceDetails',
            datatype: "json",
            colModel: [
                { label: '日期', name: 'time', index:'time',width: 40,key: true, sortable:false },
                // { label: '学年', name: 'courseAcademicYear', index:'which_index',width: 40 },
                // { label: '学期', name: 'courseAcademicTerm', index:'which_index',width: 40 },
                // { label: '教学周', name: 'courseWhichWeek', index:'which_index',width: 40 },
                // { label: '星期', name: 'courseWhichDay', index:'which_index',width: 40 },
                { label: '学生姓名', name: 'studentName', index:'student_name',width: 40, sortable:false },
                { label: '学号', name: 'studentId', index:'student_id',width: 40, sortable:false },
                { label: '班级名称', name: 'className',index:'class_name', width: 40, sortable:false },
                { label: '专业', name: 'studentProfessionName', index:'student_department',width: 40 , sortable:false},
                { label: '院系', name: 'studentDepartment', index:'student_department',width: 40 , sortable:false},
                { label: '课程名称', name: 'courseName',index:'course_name', width: 40 , sortable:false},
                { label: '节次', name: 'courseWhichIndex', index:'which_index',width: 30 , sortable:false},
                { label: '授课老师', name: 'courseTeacherName',index:'course_name', width: 30 , sortable:false},
                { label: '考勤状态', name: 'attendenceState', index:'attendence_state',width: 30, sortable:false, formatter: function(value, options, row){
                        var result;
                        if( value == '出勤')
                            result= '<span class="table-btn1 table-success">出勤</span>';
                        else if( value == '迟到')
                            result= '<span class="table-btn1 table-late">迟到</span>';
                        else if( value == '早退')
                            result= '<span class="table-btn1 table-early">早退</span>';
                        else if( value == '旷课')
                            result= '<span class="table-btn1 table-early">旷课</span>';
                        else if( value == '请假')
                            result= '<a class="table-btn1 table-absenteeism" src="'+row.imagePath+'">请假</a>';
                        else if( value == '病假')
                            result= '<a class="table-btn1 table-absenteeism" src="'+row.imagePath+'">病假</a>';
                        else if( value == '公假')
                            result= '<a class="table-btn1 table-absenteeism" src="'+row.imagePath+'">公假</a>';
                        else if( value == '私假')
                            result= '<a class="table-btn1 table-absenteeism" src="'+row.imagePath+'">私假</a>';
                        if(row.isAttendance==2)
                        {
                            result=result+'<span class="corner">2</span>';
                        }
                        return result;

                    }},
                { label: '提交人', name: 'operatorName', index:'operator_name',width: 40, sortable:false },
                { label: '提交时间', name: 'updateTime', index:'update_time',width: 60, sortable:false },
            ],
            viewrecords: true,
            height: '100%',
            rowNum: 10,
            rowList : [10,30,50],
            rownumbers: true,
            // rownumWidth: 25,
            autowidth:true,
            multiselect: false,
            pager: "#jqGridPager",
            jsonReader : {
                root: "page.list",
                page: "page.currPage",
                total: "page.totalPage",
                records: "page.totalCount"
            },
            prmNames : {
                page:"page",
                rows:"limit",
                order: "order"
            },
            gridComplete:function(){
                //隐藏grid底部滚动条
                $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "scroll" });
            }
            ,
            ondblClickRow:function(rowid){
                var rowData = $("#jqGrid").jqGrid('getRowData',rowid);
                var rowName =$("#jqGrid").jqGrid('getGridParam','colNames');
                var s="";
                var i=2;
                for(var key in rowData){
                    s=s+rowName[i++]+':'+rowData[key]+'<br> ';
                }
                // alert(s);
            }
        });
        $("#exportExcel").attr('href',baseURL+'StudentAttendenceDetails/export?token='+token);
        $.ajax({
            url: baseURL + "/classInfo/getMyClass",
            data: {
                college:college,
                profession:profession
            },
            success: function (r) {
                $("#Class").append("<option value=''>请选择班级</option>");
                for (i = 0; i < r.list.length; i++) {
                    var tname = r.list[i];
                    var tid = r.list[i];
                    $("#Class").append("<option value='" + tid + "'>" + tname + "</option>");
                }
            }
        });
    });
    function setDate(id) {
        var Nowdate=new Date();
        M=Number(Nowdate.getMonth())+1;
        var today=Nowdate.getFullYear()+"-"+fix(M)+"-"+fix(Nowdate.getDate());
        if(id=='1'){
            $("#startDate").val(today);
            $("#endDate").val(today);
        }else if(id=='2'){
            $("#startDate").val(showWeekFirstDay());
            $("#endDate").val(today);
        }if(id=='3'){
            $("#startDate").val(showMonthFirstDay());
            $("#endDate").val(today);
        }
        vm.reload();
    }
    function showWeekFirstDay()
    {
        var Nowdate=new Date();
        var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
        M=Number(WeekFirstDay.getMonth())+1
        return WeekFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(WeekFirstDay.getDate());
    }
    function showWeekLastDay()
    {
        var Nowdate=new Date();
        var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
        var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
        M=Number(WeekLastDay.getMonth())+1
        return WeekLastDay.getFullYear()+"-"+M+"-"+WeekLastDay.getDate();
    }
    function showMonthFirstDay()
    {
        var Nowdate=new Date();
        var MonthFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth(),1);
        M=Number(MonthFirstDay.getMonth())+1
        return MonthFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(MonthFirstDay.getDate());
    }
    function fix(num){
        if(num<10)
            return "0"+num;
        else return ""+num;
    }
    function showMonthLastDay()
    {
        var Nowdate=new Date();
        var MonthNextFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth()+1,1);
        var MonthLastDay=new Date(MonthNextFirstDay-86400000);
        M=Number(MonthLastDay.getMonth())+1
        return MonthLastDay.getFullYear()+"-"+M+"-"+MonthLastDay.getDate();
    }
    var vm = new Vue({
        el:'#rrapp',
        data:{
            q:{
                key: null
            },
            showList: true,
            title: null,
            StudentAttendenceDetails: {},
            updateTime: null
        },
        methods: {
            query: function () {
                var startDate=$("#startDate").val();
                var endDate=$("#endDate").val();
                var college=$("#College").val();
                var profession=$("#Profession").val();
                var class1=$("#Class").val();
                var studentId=$("#Student").val();
                var course=$("#Course").val();
                var state=$("#State").val();
                var href=baseURL+'StudentAttendenceDetails/export?token='+token+
                    "&startDate="+startDate+
                    "&endDate="+ endDate+
                    "&college="+college+
                    "&profession="+profession+
                    "&class="+class1+
                    "&studentId="+studentId+
                    "&course="+course+
                    "&state="+state;
                $("#exportExcel").attr('href',href);
                vm.reload();
            },
            reload: function () {
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam','page');
                $("#jqGrid").jqGrid('setGridParam',{
                    postData:{
                        'studentName': vm.q.key,
                        'startDate': $("#startDate").val(),
                        'endDate': $("#endDate").val(),
                        'college': $("#College").val(),
                        'profession':$("#Profession").val(),
                        'studentId':$("#Student").val(),
                        'class': $("#Class").val(),
                        'course':$("#Course").val(),
                        'state':$("#State").val()
                    },
                    page:page
                }).trigger("reloadGrid");
            },

        }
    });


</script>
<style type="text/css">
    .corner{
        background-color: red;
        color: white;
        border-radius: 50%;
        position: relative;
        top: -8px;
        left: -6px;
        font-size: 8px;
        padding: 1px 4px
    }
</style>
</body>
</html>